package challenge01;

import java.util.Scanner;

/**
 * @author DCSGO
 * @version 1.0
 * https://www.lanqiao.cn/problems/5128/learning/?contest_id=144
 * 观察样例可知：
 * 当前节点的编号 curNum * 2 - 1 即为 L 对应的编号
 * 当前节点的编号 curNum * 2 即为 R 对应的编号
 */
public class P2 {

    public static int getNum(int curNum, char direc) {
        if (direc == 'L') {
            return curNum * 2 - 1;
        } else {
            return curNum * 2;
        }
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int q = scan.nextInt();
        for (int i = 0; i < q; i++) {
            String path = scan.next();
            int curNum = 1;
            for (char direc : path.toCharArray()) {
                curNum= getNum(curNum,direc);
            }
            System.out.println(curNum);
        }
        scan.close();
    }
}

